package com.dzu.medium;

import java.util.*;

/**
 * @author ZhaoDong
 * @date 2022/10/20 9:34
 * @description 539. 最小时间差
 */
public class Test539 {

    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        list.add("23:59");
        list.add("00:00");


        System.out.println(findMinDifference(list));
    }

    public static int findMinDifference(List<String> timePoints) {

        int[] arr = new int[timePoints.size()];

        for (int i = 0; i < timePoints.size(); i++) {
            String[] split = timePoints.get(i).split(":");
            int hour = Integer.parseInt(split[0]);
            int minutes  = Integer.parseInt(split[1]);
            arr[i] = hour * 60 + minutes;
        }

        Arrays.sort(arr);


        int min = Integer.MAX_VALUE;
        for (int i = 1; i < arr.length; i++) {
            min = Math.min(min, arr[i] - arr[i - 1]);
        }

        return Math.min(min, arr[0] - arr[arr.length - 1] + 1440);

    }
}
